//
//  MoreMusicController.m
//  SleepingElf
//
//  Created by karong on 2023/10/20.
//

#import "MoreMusicController.h"
#import "ClassListRequest.h"
#import "HomeMusicCell.h"
#import "HomeModel.h"

@interface MoreMusicController ()
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) ClassListRequest * request;

@end

@implementation MoreMusicController

- (void)viewDidLoad {
    [super viewDidLoad];
    ClassListRequest * request = [ClassListRequest new];
    request.classify_id = self.classify_id;
    self.request = request;
    [self loadClassListRequest];
}

- (void)loadClassListRequest {
    [ClassListRequest loadSleepPlayClasslistWithClassify_id:self.classify_id success:^(HomeClassify * obj) {
        self.title = obj.name;
    } failed:^(NSURLResponse * _Nonnull response, NSError * _Nonnull error, id  _Nonnull responseObject) {
    }];
}

- (BOOL)disableAutoBeginRefresh {
    return YES;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HomeMusicCell * homeMusicCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeMusicCell" forIndexPath:indexPath];
    [homeMusicCell setDataWithObject:self.dataArray[indexPath.row]];
    return homeMusicCell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([[PlayerManager shared]musicIsPlaying:self.dataArray[indexPath.row]]) {
        [[PlayerManager shared]pause];
    }
    else {
        [[PlayerManager shared]playWithMusic:self.dataArray[indexPath.row]];
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = floor((SEScreenWidth - 13 - 13 - 32) / 2.0f);
    size.height = size.width;
    return size;
}



@end
